# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=githound
_pkgname=git-hound
pkgver=v3.2.r0.g15701b7
pkgrel=1
pkgdesc='Find secret information in git repositories.'
groups=('blackarch' 'blackarch-code-audit' 'blackarch-recon')
arch=('x86_64' 'aarch64')
url='https://github.com/tillson/git-hound'
license=('MIT')
depends=()
makedepends=('git' 'go')
source=("git+https://github.com/tillson/$_pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $_pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

build() {
  cd $_pkgname

  GOPATH="$srcdir" go mod download
  GOPATH="$srcdir" go build \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-s -w" \
    -o $pkgname .
}

package() {
  cd $_pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  install -Dm 644 -t "$pkgdir/usr/share/$pkgname/" regex.yml $pkgname
  install -Dm 644 config.example.yml "$pkgdir/usr/share/$pkgname/config.yml"
  cp -a rules rules-generator "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec ./$pkgname "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname" "$pkgdir/usr/share/$pkgname/$pkgname"
}

